package cn.smile.controller.core;

import cn.smile.bean.dto.core.ShareUserDTO;
import cn.smile.bean.form.core.share.QueryShareForm;
import cn.smile.bean.form.core.share.UpdateBindDicForm;
import cn.smile.business.core.IShareRelationService;
import cn.smile.commons.response.MyResult;
import com.baomidou.mybatisplus.core.metadata.IPage;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/shareRelation")
public class ShareRelationController {

    @Resource
    private IShareRelationService service;

    @GetMapping(value = "getShareCode")
    public MyResult<String> getShareCode() {
        return MyResult.OK(service.getShareCode());
    }

    @GetMapping(value = "bindShare")
    public MyResult<Boolean> bindShare(@RequestParam("shareCode") String shareCode) {
        return MyResult.OK(service.bindShare(shareCode));
    }

    @PostMapping(value = "getSharePage")
    public MyResult<IPage<ShareUserDTO>> getSharePage(@RequestBody QueryShareForm form) {
        return MyResult.OK(service.getSharePage(form));
    }

    @PostMapping(value = "getShareList")
    public MyResult<List<ShareUserDTO>> getShareList(@RequestBody QueryShareForm form) {
        return MyResult.OK(service.getShareList(form));
    }

    @GetMapping(value = "delBind")
    public MyResult<Boolean> delBind(@RequestParam("shareUserId") String shareUserId) {
        return MyResult.OK(service.delBind(shareUserId));
    }

    @PostMapping(value = "updateRelationDic")
    public MyResult<Boolean> updateRelationDic(@Valid @RequestBody UpdateBindDicForm form) {
        return MyResult.OK(service.updateRelationDic(form));
    }
}
